<html class="panel-fit">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE">
    <title>编辑菜单</title>

    <link href="/public/static/css/ThemesEasyui/gray/easyui.css" rel="stylesheet">

    <link href="/public/static/css/ThemesEasyui/red/exEasyui.css" rel="stylesheet">

    <link href="/public/static/css/ThemesEasyui/icon.css" rel="stylesheet">


    <link href="/public/static/css/FormPage.css" rel="stylesheet">
    <link href="/public/static/css/ListPage.css" rel="stylesheet">





    <script src="/public/static/js/jquery-2-0-0-min.js"></script>
    <script src="/public/static/js/jquery.easyui.min.js"></script>
    <script src="/public/static/js/jquery-easyui-1-4-0-lang-zh_CN.js"></script>
    <script type="text/javascript">
        var keywords = "";

        // $.ajax({
        //     url: "/keyword/keyword.xml",
        //     dataType: 'xml',
        //     type: 'GET',
        //     timeout: 2000,
        //     error: function (xml) {

        //        // alert("加载XML 文件出错！");
        //     },
        //     success: function (xml) {

        //         $(xml).find("MetaKeywords").each(function (i) {
        //             keywords = $(this).text();


        //         });
        //     }
        // });


        function load() {
            var ts = $("#frameLoadTs", window.parent.document);
            ts.hide();
        }
    </script>
    <script src="/public/static/js/common-helper.js"></script>


    <script src="/public/static/js/knockout-2-2-1.js"></script>

    <script src="/public/static/js/knockout-mapping-2-4-1.js"></script>


    <script src="/public/static/js/common-binder-treelist-view.js"></script>

    <script src="/public/static/js/common-binder-form-edit.js"></script>
    <script src="/public/static/js/common-binder-list-edit.js"></script>

    <script src="/public/static/js/VMFormData.js"></script>

    <script type="text/javascript">
        var data = { "FormData": { "ItemData": { "ID": 25, "AdminGroupName": "测试管理组1" }, "RecordID": 25 }, "ItemMetadata": { "ID": { "DisplayName": "编号", "DataTypeInfo": "TypeInteger", "DisplayWidth": 100, "DisplayOrder": 1, "EnableView": false, "EnableEdit": false, "IsRequired": true }, "AdminGroupName": { "DisplayName": "管理员组名称", "DataTypeInfo": "TypeSinglelineText", "DisplayWidth": 100, "DisplayOrder": 3, "EnableView": true, "EnableEdit": true, "IsRequired": true } }, "MetaData": { "ID": { "DisplayName": "编号", "DataTypeInfo": "TypeInteger", "DisplayWidth": 100, "DisplayOrder": 1, "EnableView": false, "EnableEdit": false, "IsRequired": true }, "AdminGroupName": { "DisplayName": "管理员组名称", "DataTypeInfo": "TypeSinglelineText", "DisplayWidth": 100, "DisplayOrder": 3, "EnableView": true, "EnableEdit": true, "IsRequired": true } } };
        //  data = "http://lhl.sh.com:8080/admin/user/getmenus.html?id={$id}";

        var viewModel = new VMFormData(data);
        var gridListHandler = new listGridHandler(data, "gridListHandler", 'gridList');
        // viewModel.paramNewUrl = "http://315yun.com/api/LBAdminGroup/Add";

        // viewModel.paramUpdateUrl = "http://315yun.com/api/LBAdminGroup/Update";
        // viewModel.paramUpdateUrl = "/admin/user/save_auth";
        gridListHandler.enableFilter = false;

        function aa() {
                $('#gridList').treegrid('selectAll');

                var selects = $('#gridList').treegrid('getSelections');
                var str = "{";
                var viewStr = [];
                var addStr = [];
                var editStr = [];
                var delStr=[];
                var createStr=[];
                var exportStr=[];
                var downloadlabelStr=[];
                var snimportStr=[];
                var delayStr=[];
                var addcardStr=[];
                var activateStr=[];
                var fixStr=[];


                var id = "{$id}";
                // var delStr=[];


                for (i = 0; i < selects.length; i++) {
                    str += "'PowerItemData" + i + "':{";
                    if (data.FormData.RecordID > 0) {

                        str += "'PowerID':" + selects[i].PowerID + ",";
                    }
                    str += "'MenuID':" + selects[i].id + ",";
                    if ($("#formPowerLook" + selects[i].id)[0].checked) {
                        str += "'LookPower':1,";
                        // 追加可查看的Id
                        viewStr.push(selects[i].id);
                    } else {
                        str += "'LookPower':0,";
                    }

                    if ($("#formPowerAdd" + selects[i].id)[0].checked) {
                        str += "'addPower':1,";
                        // 追加可增加的Id
                        addStr.push(selects[i].id);
                    } else {
                        str += "'addPower':0,";
                    }

                    if ($("#formPowerEdit" + selects[i].id)[0].checked) {
                        str += "'editPower':1,";
                        // 追加可编辑的Id
                        editStr.push(selects[i].id);
                    } else {
                        str += "'editPower':0,";
                    }

                    if($("#formPowerDel"+selects[i].id)[0].checked){
                        str+="'delPower':1";
                        // 追加可删除的Id
                        delStr.push(selects[i].id);
                    }else{
                        str+="'delPower':0";
                    }

                    if($("#formPowerCreatelabel"+selects[i].id)[0].checked){
                        str+="'createlabelPower':1";
                        // 追加可生成标签的Id
                        createStr.push(selects[i].id);
                    }else{
                        str+="'createlabelPower':0";
                    }

                    if($("#formPowerExport"+selects[i].id)[0].checked){
                        str+="'exportPower':1";
                        // 追加可导出的Id
                        exportStr.push(selects[i].id);
                    }else{
                        str+="'exportPower':0";
                    }

                    if($("#formPowerDownloadlabel"+selects[i].id)[0].checked){
                        str+="'downloadlabelPower':1";
                        // 追加可下载标签的Id
                        downloadlabelStr.push(selects[i].id);
                    }else{
                        str+="'downloadlabelPower':0";
                    }

                    if($("#formPowerSnimport"+selects[i].id)[0].checked){
                        str+="'snimportPower':1";
                        // 追加可导入序列号的Id
                        snimportStr.push(selects[i].id);
                    }else{
                        str+="'snimportPower':0";
                    }

                    if($("#formPowerDelay"+selects[i].id)[0].checked){
                        str+="'delayPower':1";
                        // 追加可延期的Id
                        delayStr.push(selects[i].id);
                    }else{
                        str+="'delayPower':0";
                    }

                    if($("#formPowerAddcard"+selects[i].id)[0].checked){
                        str+="'addcardPower':1";
                        // 追加可添加保修卡的Id
                        addcardStr.push(selects[i].id);
                    }else{
                        str+="'addcardPower':0";
                    }

                    if($("#formPowerActivate"+selects[i].id)[0].checked){
                        str+="'activatePower':1";
                        // 追加可审核设备激活的Id
                        activateStr.push(selects[i].id);
                    }else{
                        str+="'activatePower':0";
                    }

                    if($("#formPowerFix"+selects[i].id)[0].checked){
                        str+="'fixPower':1";
                        // 追加可审核维修的Id
                        fixStr.push(selects[i].id);
                    }else{
                        str+="'fixPower':0";
                    }
                    
                    

                    if (i == selects.length - 1) {
                        str += "}";
                    } else {
                        str += "},";
                    }
                }
                str += "}";
                // console.log("AA"+str);
                // return false;

                // console.log("ID:" + id);
                // console.log("查看的ID：" + viewStr);

                // data.FormData.PowerData= eval('(' + str + ')');
                // data.FormData.Menurows=selects.length;
                submitClick(id, viewStr, addStr,editStr,delStr,createStr,exportStr,downloadlabelStr,snimportStr,delayStr,addcardStr,activateStr,fixStr);

                //  return false;
            }



        $(function () {
            ko.applyBindings(viewModel);
            gridListHandler.bindFilter($('#gridList'));

            

            $("#tabEnumType_EnumValue").append($("#Tool").html());
        });


        function submitClick(id, viewStr, addStr,editStr,delStr,createStr,exportStr,downloadlabelStr,snimportStr,delayStr,addcardStr,activateStr,fixStr) {
            // console.log(id)
            // console.log(delStr)
            $.post("save_auth.html", { "id": id, "auth[]": viewStr, "add[]": addStr ,"edit[]": editStr,"del[]": delStr,"createlabel[]": createStr,"export[]": exportStr,"downloadlabel[]": downloadlabelStr,"snimport[]": snimportStr,"delay[]": delayStr,"addcard[]": addcardStr,"activate[]": activateStr,"fix[]": fixStr }, function (res) {
                if (res.status == 1) {
                    alert("设置成功")
                    closeDialog();
                } else {
                    // $.messager.alert('提示', data.msg, 'info');
                    // return;
                    alert("提交失败，请刷新重试！",data.msg);

                }
            });
        }


        function AllSelect(obj, type) {
            $('#gridList').treegrid('selectAll');
            var selects = $('#gridList').treegrid('getSelections');
            if (obj.checked) {
                $("#" + type).html("全不选");
                for (i = 0; i < selects.length; i++) {
                    $("#" + type + selects[i].id)[0].checked = true;
                }
            } else {
                $("#" + type).html("全选");
                for (i = 0; i < selects.length; i++) {
                    $("#" + type + selects[i].id)[0].checked = false;
                }
            }


        }

        function ReSelect(obj, type) {
            $('#gridList').treegrid('selectAll');
            var selects = $('#gridList').treegrid('getSelections');

            for (i = 0; i < selects.length; i++) {
                if ($("#" + type + selects[i].id)[0].checked) {
                    $("#" + type + selects[i].id)[0].checked = false;
                } else {
                    $("#" + type + selects[i].id)[0].checked = true;
                }
            }

        }
    </script>
    <style>
        .items{
            float: left;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 12px;
            width: 200px;
            margin-bottom: 6px;
        }
        .items input[type="checkbox" i] {
            margin-top: 10px !important;
        }
    </style>


</head>
<!-- onload="load()" -->
<body onload="load()" class="panel-noscroll" style="">
    <div id="tabState" class="easyui-tabs" fit="true">
        <div title="编辑菜单">
            <form id="formState">
                <table class="form_table" style="width:97%">
                    <tr class="form_tr" style="display: none;">

                        <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                            管理员组名称
                        </th>
                        <td style="width:755px;padding-left:8px;" colspan="1" class="form_td form_td_content">
                            <input class="easyui-validatebox" type="text" validtype="workflowStateIsStart"
                                id="formState_AdminGroupName" style="width:600px;"
                                data-bind="Value: form.AdminGroupName"
                                data-options="required:true,tipPosition:'right'," />

                        </td>

                    </tr>
                    <tr>
                        <td style="width: 100%;"><div id="tabEnumType_EnumValue" style="width: 100%;display: none;"></div></td>
                    </tr>
                    <tr class="form_tr">
                        <td style="width: 100%;">
                            
                            <!-- <div id="tabEnumType_EnumValue" class="easyui-tabs"  data-options="tools:'#toolbarEnumType_EnumValue',border:false" style="width: 100%; "> -->
                                <!-- <div title="权限设置" data-options="border:false"> -->

                                    <div data-options="region:'center',border:false">

                                        <table id="gridList" exusagetype="SingleSelection"
                                            data-options="url:'/admin/user/getmenus.html?id={$id}',method:'POST',rownumbers: true ,idField: 'id' ,treeField: 'text'">

                                            <thead>
                                                <tr>

                                                    <th data-options="field:'text'" width="160">菜单名称</th>
                                                    <th exfield="LookPower" data-options="field:'LookPower',formatter:gridListHandler.formatCheckBoxLook,width:80,halign:'center',align:'center',filterable:true">查看权限</th>
                                                    <th exfield="addPower" data-options="field:'addPower',formatter:gridListHandler.formatCheckBoxAdd,width:80,halign:'center',align:'center',filterable:true">新增权限</th>
                                                    <th exfield="editPower" data-options="field:'editPower',formatter:gridListHandler.formatCheckBoxEdit,width:80,halign:'center',align:'center',filterable:true">修改权限</th>
                                                    <th exfield="delPower" data-options="field:'delPower',formatter:gridListHandler.formatCheckBoxDel,width:80,halign:'center',align:'center',filterable:true">删除权限</th>
                                                    <th exfield="createlabelPower" data-options="field:'createlabelPower',formatter:gridListHandler.formatCheckBoxCreatelabel,width:88,halign:'center',align:'center',filterable:true">生成标签权限</th>
                                                    <th exfield="exportPower" data-options="field:'exportPower',formatter:gridListHandler.formatCheckBoxExport,width:88,halign:'center',align:'center',filterable:true">导出权限</th>
                                                    <th exfield="downloadlabelPower" data-options="field:'downloadlabelPower',formatter:gridListHandler.formatCheckBoxDownloadlabel,width:88,halign:'center',align:'center',filterable:true">下载标签权限</th>

                                                    <th exfield="snimportPower" data-options="field:'snimportPower',formatter:gridListHandler.formatCheckBoxSnimport,width:88,halign:'center',align:'center',filterable:true">导入序列号权限</th>
                                                    <th exfield="delayPower" data-options="field:'delayPower',formatter:gridListHandler.formatCheckBoxDelay,width:88,halign:'center',align:'center',filterable:true">延期权限</th>
                                                    <th exfield="addcardPower" data-options="field:'addcardPower',formatter:gridListHandler.formatCheckBoxAddcard,width:88,halign:'center',align:'center',filterable:true">添加保修卡权限</th>
                                                    <th exfield="activatePower" data-options="field:'activatePower',formatter:gridListHandler.formatCheckBoxActivate,width:88,halign:'center',align:'center',filterable:true">设备激活审核权限</th>
                                                    <th exfield="fixPower" data-options="field:'fixPower',formatter:gridListHandler.formatCheckBoxFix,width:88,halign:'center',align:'center',filterable:true">维修审核权限</th>
  
                                                    

                                                    <th exfield="addPower_v" data-options="field:'addPower_v',hidden:true,width:80,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="editPower_v" data-options="field:'editPower_v',hidden:true,width:80,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="delPower_v" data-options="field:'delPower_v',hidden:true,width:80,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="createlabelPower_v" data-options="field:'createlabelPower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="exportPower_v" data-options="field:'exportPower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="downloadlabelPower_v" data-options="field:'downloadlabelPower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>

                                                    <th exfield="snimportPower_v" data-options="field:'snimportPower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="delayPower_v" data-options="field:'delayPower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="addcardPower_v" data-options="field:'addcardPower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="activatePower_v" data-options="field:'activatePower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>
                                                    <th exfield="fixPower_v" data-options="field:'fixPower_v',hidden:true,width:88,halign:'center',align:'center',filterable:true"></th>
                                                    

                                                </tr>
                                            </thead>
                                        </table>

                                    </div>
                                <!-- </div> -->
                            <!-- </div> -->

                        </td>
                    </tr>

                    <tr class="form_tr">
                        <td class="form_button_panel" colspan="6" style="padding-right:8px">
                            <a href="#" onclick="aa()" class="easyui-linkbutton form-toolbar-button" data-options="iconCls:'icon-save'">保存</a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>

    <div id="Tool" style="width:100%; display:none;">
        <div style="background-color: rgba(0,0,0,0.1);padding: 10px 0;">
            <div class="items">
                查看权限 <span id="formPowerLook">全选</span><input onclick="AllSelect(this,'formPowerLook')" type="checkbox" /><span>反选</span><input onclick="ReSelect(this,'formPowerLook')" type="checkbox" />
            </div>
            <div class="items">
                增加权限 <span id="formPowerAdd">全选</span><input onclick="AllSelect(this,'formPowerAdd')" type="checkbox" /><span>反选</span><input onclick="ReSelect(this,'formPowerAdd')" type="checkbox" />
            </div>
            <div class="items">
                修改权限 <span id="formPowerEdit">全选</span><input onclick="AllSelect(this,'formPowerEdit')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerEdit')" type="checkbox" />
            </div>
            <div class="items">
                删除权限 <span id="formPowerDel">全选</span><input onclick="AllSelect(this,'formPowerDel')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerDel')" type="checkbox" />
            </div>
            <div class=items>
                生成标签权限 <span id="formPowerCreatelabel">全选</span><input onclick="AllSelect(this,'formPowerCreatelabel')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerCreatelabel')" type="checkbox" />
            </div>
            <div class="items">
                导出权限 <span id="formPowerExport">全选</span><input onclick="AllSelect(this,'formPowerExport')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerExport')" type="checkbox" />
            </div>
            <div class="items">
                下载标签权限 <span id="formPowerDownloadlabel">全选</span><input onclick="AllSelect(this,'formPowerDownloadlabel')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerDownloadlabel')" type="checkbox" />
            </div>
            <div class="items">
                导入序列号权限 <span id="formPowerSnimport">全选</span><input onclick="AllSelect(this,'formPowerSnimport')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerSnimport')" type="checkbox" />
            </div>
            <div class="items">
                延期权限 <span id="formPowerDelay">全选</span><input onclick="AllSelect(this,'formPowerDelay')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerDelay')" type="checkbox" />
            </div>
            <div class="items">
                添加保修卡权限 <span id="formPowerAddcard">全选</span><input onclick="AllSelect(this,'formPowerAddcard')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerAddcard')" type="checkbox" />
            </div>
            <div class="items">
                设备激活审核 <span id="formPowerActivate">全选</span><input onclick="AllSelect(this,'formPowerActivate')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerActivate')" type="checkbox" />
            </div>
            <div class="items">
                维修审核权限 <span id="formPowerFix">全选</span><input onclick="AllSelect(this,'formPowerFix')" type="checkbox" /> <span>反选</span><input onclick="ReSelect(this,'formPowerFix')" type="checkbox" />
            </div>
            <div style="clear:both;"></div>

            
        </div>
    </div>
</body>

</html>